package com.cheerscpl.handler;

import com.cheerscpl.Task;
import com.cheerscpl.annotation.EventHandler;
import com.cheerscpl.service.TaskService;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by chenpuliang on 2017/6/5.
 */
@EventHandler
public class TaskHandler {

    private static final Logger logger = LoggerFactory.getLogger(TaskHandler.class);

    @Autowired
    private TaskService taskService;

    @Subscribe
    @AllowConcurrentEvents
    public void subscribe(Task task){
        taskService.addTask(task);
        logger.info("task : {} add to queue success.", task.getName());
    }

}
